#!/usr/bin/python
# coding=utf-8
'''
pip3 install Pillow
'''
import os
import shutil
import time
import sys
from PIL import Image
   
#图片批处理  
def timage(filename,outpath,outname,size,height):  
        print(filename)
        print(outpath)
        print(outname)
        print(size)
        #判断opfile是否存在，不存在则创建  
        if (os.path.isdir(outpath)==False):  
            os.mkdir(outpath)  
        im = Image.open(filename)  
        im_ss = im.resize(( int(size),  int(height)),Image.ANTIALIAS)  
        im_ss.save(outpath+'/'+outname,"png")  

# 读取处理尺寸
def readAndfile(pic,refilename,outpath):
    with open(refilename,'r') as f:
        while True:
            line = f.readline().strip('\n')
            if len(line) != 0:
               array=line.split()
               if( not (array[0] == '#')) :
                    timage(pic,outpath,array[0],array[1],array[2])
            else:
                break


# 读取参数
print(sys.argv)
args = sys.argv
if len(args) < 2:
    print('args error!')
else:
    pic = args[1]
    if pic.endswith('.png') or pic.endswith('.jpeg'):
        print('start ! >>>>> ',pic)
        readAndfile(pic,"listfilename",'icons')
    else:
        print('image error!')
